package com.woniuxy.Filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.net.URI;

/**
 * @Author：向天浩
 * @Date：2022/2/15 11:48
 * @Description :这是使用注解直接生成过滤器的方式
 */
@WebFilter(urlPatterns = "/*",filterName = "FilterOne")//过滤哪些url，过滤器的名字
@Component//注册成bean对象的注解
public class FilterOne implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        //获取开始时间
        long startTime = System.currentTimeMillis();
        //进入过滤器的时间
        System.out.println("进入过滤器的时间;"+startTime+"ms");
        chain.doFilter(request, response);
        System.out.println("流程结束返回到过滤器的时间;"+(System.currentTimeMillis() - startTime)+"ms");


    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}
